<?php

class Membership_model extends Model {

	function validate()
	{
		$this->db->where('loginn', $this->input->post('username'));
		$this->db->where('password', $this->input->post('password'));
		$query = $this->db->get('loguin');
		
		if($query->num_rows == 1)
		{
			return true;
		}
		return false;
	}

    function es_administrador($username)
    {

        $this->db->select('*');
        $this->db->from('empleado');
        $this->db->join('loguin', 'loguin.carnet = empleado.carnet');
        $this->db->where('loguin.loginn', $username);
        $result = $this->db->get();

        if($result->num_rows == 1)
        {
            $empleado = $result->row();
            if ($empleado->tipo =="administrador" )
            {
                return true;
            }
            else

            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }

    function es_operador($username)
    {

        $this->db->select('*');
        $this->db->from('empleado');
        $this->db->join('loguin', 'loguin.carnet = empleado.carnet');
        $this->db->where('loguin.loginn', $username);
        $result = $this->db->get();

        if($result->num_rows == 1)
        {
            $empleado = $result->row();
            if ($empleado->tipo =="operador" )
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
	
	function create_member()
	{
		
		$new_member_insert_data = array(
            'carnet'=>$this->input->post('carnet'),
			'nombre' => $this->input->post('nombre'),
			'apellido' => $this->input->post('apellido'),
			///'email_address' => $this->input->post('email_address'),
			'loginn' => $this->input->post('loginn'),
			'password' => $this->input->post('password')
		);
		log_message('INFO',"*************".print_r($new_member_insert_data,true));
		$insert = $this->db->insert('loguin', $new_member_insert_data);
		return $insert;
	}
    //-----lista de carnet del empleado

    function obtenerListaempleado()
    {
        $query = $this->db->query("SELECT carnet FROM empleado;");
        return $query->result_array();
    }
}